import com.mysql.jdbc.Driver;

import java.sql.*;

public class statementQueryTest {
    public static void main(String[] args) throws SQLException {
        //注册驱动
        DriverManager.registerDriver(new Driver());
            //导import com.mysql.jdbc.Driver;包

        //获取链接
            //java需要导入链接数据库的基本信息
            //ip地址 端口号 账号 密码 连接数据库的名称
        Connection connection1 =
                DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/atguigudb","root","111111");
                //参数1 url ip地址
                    //写法 jdbc:mysql://127.0.0.1:13306/atguigudb
                // 用户名
                //账号密码
        //创建statement
        Statement statement = connection1.createStatement();
        //发送sql语句
        String sql = "SELECT first_name , last_name FROM employees";
        ResultSet resultSet = statement.executeQuery(sql);
        //结果集解析
        int cnt = 0;
        while (resultSet.next()){
            String first_name = resultSet.getString("first_name");
            String last_name = resultSet.getString("last_name");
            System.out.println(first_name + "----" + last_name);
            cnt++;
        }
        System.out.println(cnt);
        //关闭资源
        resultSet.close();
        statement.close();
        connection1.close();

    }
}